package com.itheima.mapper;

import com.itheima.pojo.Borrow;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BorrowMapper {
    /**
     * 插入借阅记录
     *
     * @param borrow
     */
    @Insert("insert into cl_borrow (user_id,book_id,create_time,update_time) " +
            "values (#{userId},#{bookId},#{createTime},#{updateTime})")
    void insert(Borrow borrow);

    /**
     * 根据用户id，展示借阅记录
     *
     * @param userId
     * @return
     */
    @Select("select * from cl_borrow where user_id = #{userId}")
    List<Borrow> getByUserId(Integer userId);

    /**
     * 根据id查询借阅记录
     *
     * @param id
     * @return
     */
    @Select("select * from cl_borrow where id = #{id}")
    Borrow getById(Integer id);

    /**
     * 归还图书，删除借阅记录
     *
     * @param id
     */
    @Delete("delete from cl_borrow where id = #{id}")
    void delete(Integer id);

}
